package com.wangjiang.foundation.common.util;

import java.util.ArrayList;
import java.util.List;

/**
 * java 数组工具类
 * @author wangjiang
 * @date 2019-12-17
 */
public class ArrayUtils {

    /**
     * 获取某个数组最后几个元素，并返回一个新的数组
     * @param targetList
     * @param accessTokenNumberPerTime
     * @return
     */
    public static List<String> getLastNumberArray(
            List<String> targetList,
            Integer accessTokenNumberPerTime) {
        List resultList = new ArrayList();
        Integer len = targetList.size();
        if (accessTokenNumberPerTime > 0 && len > 0) {
            for (int i = 0; i < accessTokenNumberPerTime; i++) {
                int targetIndex = (len - accessTokenNumberPerTime + i);
                resultList.add(targetList.get(targetIndex));
            }
        }

        return resultList;
    }

}
